home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Code_Fragments / support.c < prev   
C/C++ Source or Header  |  1998-09-18  |  5KB  |  146 lines

  1. /*
  2.        First routine is a simple ASL filerequester and the second does
  3.        show you how to use SelectionList() to get a destination.
  4.  
  5. */
  6.  
  7. #include <proto/dos.h>
  8. #include <proto/exec.h>
  9. #include <proto/asl.h>
  10. #include <proto/utility.h>
  11. #include <proto/intuition.h>
  12.  
  13. extern struct Library *DOpusBase;
  14.  
  15. #include <dopus/modules.h>
  16.  
  17. /********************************************************************/
  18. // since I did saw very strange stuff done also by average coders,
  19. // I show you also how to work with a simple ASL filerequester...
  20.  
  21. #define TAGIF(expression,tag) ((expression) ? tag : TAG_IGNORE)
  22.  
  23. // a drawers only requester
  24. #define FLG_DRAWER_ONLY       1 << 0
  25.  
  26. // requester should have half width of the supplied window, same height
  27. // and should be centered...
  28. #define FLG_CENTER            1 << 1
  29.  
  30.  
  31. STRPTR GetFile( struct Window *win, ULONG flags, STRPTR title,
  32.                 STRPTR initial_path, STRPTR initial_file,
  33.                 STRPTR pattern, STRPTR dest )
  34. {
  35.         struct FileRequester *request;
  36.         
  37.         if( request = AllocAslRequestTags( ASL_FileRequest,
  38.                                            ASLFR_Window, win,
  39.                                            ASLFR_SleepWindow, TRUE,
  40.                                            ASLFR_TitleText, title,
  41.                                            TAGIF( initial_path, ASLFR_InitialDrawer ), initial_path,
  42.                                            TAGIF( initial_file, ASLFR_InitialFile ), initial_file,
  43.                                            TAGIF( pattern, ASLFR_InitialPattern ), pattern,
  44.                                            TAGIF( flags & FLG_DRAWER_ONLY, ASLFR_DrawersOnly ), TRUE,
  45.                                            TAGIF( flags & FLG_CENTER, ASLFR_InitialLeftEdge ), win->LeftEdge+win->Width/4,
  46.                                            TAGIF( flags & FLG_CENTER, ASLFR_InitialTopEdge ), win->TopEdge ,
  47.                                            TAGIF( flags & FLG_CENTER, ASLFR_InitialWidth ), win->Width/2 ,
  48.                                            TAGIF( flags & FLG_CENTER, ASLFR_InitialHeight ), win->Height ,
  49.                                            TAG_DONE ) )
  50.           {
  51.              if( AslRequest(request, NULL) )
  52.                {
  53.                   // at this place there exist many strange constructions...
  54.                   // here is the style it should be done... !
  55.  
  56.                   GetCurrentDirName( dest, 256 );
  57.  
  58.                   // AddPart() does overwrite an existing path, if the part
  59.                   // to add is already a complete path...
  60.  
  61.                   AddPart( dest, request->fr_Drawer, 256 );
  62.  
  63.                   if( !(flags & FLG_DRAWER_ONLY) )
  64.                        AddPart( dest, request->fr_File, 256 );
  65.                }
  66.              else
  67.                {
  68.                   if( !IoErr() )
  69.                        dest[0] = 0;
  70.                }
  71.                   
  72.              FreeAslRequest( request );
  73.           }
  74.         return dest;
  75. }
  76.  
  77. /********************************************************************/
  78. // Usage of SelectionList()...
  79.  
  80.  
  81. typedef
  82. {
  83.      IPCData           *ipc;          // your IPC pointer
  84.      struct Screen     *screen;       // DOpus screen pointer
  85.      Att_List          *destlist;     // list to hold all sources (not freed here !)
  86.      DOpusCallbackInfo *dc;           // pointer (!) to the initialized structure
  87.  
  88.      /* receiving datas ... */
  89.  
  90.      APTR               destpath;     // choosed destination listerhandle
  91.      struct Window     *destwin;      // the window pointer of it
  92.  
  93.      char               outpath[256]; // does contain afterwards the full destination path
  94.  
  95. }    Data;
  96.  
  97. // if this function does return NULL, this indicate the user has
  98. // not choosed a dir
  99. // if cd->destpath is NULL, the user has choosed a path where no destination
  100. // lister exists.
  101.  
  102. // the needed locale strings should be no problem for you...
  103.  
  104. BOOL AskDest( Data *cd )
  105. {
  106.      short seldir = 0;
  107.      APTR path;
  108.  
  109.      cd->destpath = NULL;
  110.         
  111.      cd->destlist = Att_NewList( LISTF_POOL );
  112.                   
  113.      while( (path = cd->dc->dc_GetDest(IPCDATA(cd->ipc), cd->outpath)) )
  114.        {
  115.           Att_NewNode( cd->destlist, cd->outpath, (ULONG) path, ADDNODEF_SORT|ADDNODEF_EXCLUSIVE);
  116.           cd->dc->dc_EndDest( IPCDATA(cd->ipc), TRUE );
  117.        }
  118.                                   
  119.      if( Att_NodeCount(cd->destlist) > 1 )
  120.        {
  121.           seldir = SelectionList( cd->destlist, NULL, cd->screen,
  122.                                   DOpusGetString(locale, MSG_CHOOSE_DIR),
  123.                                   0, SLF_DIR_FIELD, cd->outpath,
  124.                                   DOpusGetString(locale, MSG_OKAY),
  125.                                   DOpusGetString(locale, MSG_CANCEL) );
  126.  
  127.           if( seldir < 0 )
  128.             {
  129.                if( strlen(cd->outpath) )
  130.                     return TRUE;
  131.  
  132.                return FALSE;
  133.             }
  134.                                           
  135.           strcpy( cd->outpath, Att_NodeName(cd->destlist, seldir) );
  136.        }
  137.      else
  138.           strcpy( cd->outpath, Att_NodeName(cd->destlist, 0) );
  139.                 
  140.      cd->destpath = (APTR) Att_FindNode(cd->destlist, seldir)->data;
  141.      cd->destwin  = cd->dc->dc_GetWindow( cd->destpath );
  142.  
  143.      return TRUE;
  144. }
  145.  
  146.